<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    
    <title>后台管理</title>
    
	<link rel="stylesheet" type="text/css" href="<%=path%>/JS/extjs/resources/css/ext-all.css" />
	<link rel="stylesheet" type="text/css" href="<%=path%>/JS/extjs/ux/statusbar/css/statusbar.css" />
	
	<script type="text/javascript" src="<%=path%>/JS/extjs/adapter/ext-base.js"></script>
	<script type="text/javascript" src="<%=path%>/JS/extjs/ext-all.js"></script>
	<script type="text/javascript" src="<%=path%>/JS/extjs/ext-lang-zh_CN.js"></script>
	<script type="text/javascript" src="<%=path%>/JS/jquery-1.7.2.js"></script>
	
	
	<link rel="stylesheet" type="text/css" href="<%=path%>/JS/extjs/ux/statusbar/css/statusbar.css" />
	<script type="text/javascript" src="<%=path%>/JS/extjs/ux/statusbar/StatusBar.js"></script>
	<script type="text/javascript" src="<%=path%>/JS/extjs/ux/statusbar/ValidationStatus.js"></script>

	
	<script type="text/javascript">
		
	
	</script>
  </head>
  
  <body>
  	<s:hidden id="menu" value="#request.parentmenulist"></s:hidden>
    <input type="hidden" id="parentmenu" value="#request.parentmenulist"/>
    
    <script type="text/javascript">
   // var arrMenu = new Array();
	$(function(){
		//加载菜单项
		/*	$.ajax({  
				url:'adminMenu',  
				type:'POST',  
				data:"{}",  
				dataType:'json',
				timeout: 100000,
				async:true,               
				error: function(a){                     
					alert('出错了');                 
				},   
				success:function (data) { 
					arrMenu = data.menuList; 
				    //$("#allUser").append("输出了：id:" + data.hello);  
				    alert(arrMenu);
				    //addToolMenu();
				}  
				});*/
	});

    function InitMain(){
        var toolbar = new Ext.Toolbar({
            id:'toolbar',
            border:'false',
            x:0,
            y:0,
            items:[{
                	id:'index',
                	text:'首页',
                	xtype:'tbbutton',
                	cls:'x-btn-text.icon',
                	handler:function(){
            			var tabpaneltemp = Ext.getCmp("home");
            			var tabpanel = Ext.getCmp("tabpanel");
            			//alert(tabpaneltemp);
            			if(tabpaneltemp == null){
                			//alert(1111111);
							tabpaneltemp = new Ext.Panel({
								id : "home",
								title : "首页",
								xtype : "panel",
								layout : "fit",
								border : "false",
								frame : "false",
								closable : "true",
								html : "<b><s:property value="#session.adminUser.username"/></b>,欢迎你进入后台管理系统"
							});
							tabpanel.add(tabpaneltemp);
							
						}
        				tabpanel.setActiveTab(tabpaneltemp);//显示打开的页签
            		}
            	}
                  ]
        });
        var tabpanel = new Ext.TabPanel({
        	id:"tabpanel",
        	activeTab:0,
        	autoWidth:true,
        	border:false,
        	frame:false,
        	items : [
        	         {
            	         id:"home",
            	        xtype : "panel",
            	        title : "首页",
            	        layout : "fit",
            	        closable : "true",
            	        border : "false",
            	        frame : "false",
            	        html : "<b><s:property value="#session.adminUser.username"/></b>，欢迎你进入后台管理系统 " 
            	     }
        	]
        });
        var northPanel = new Ext.Panel({
            id:'northPanel',
            region:'north',
            //height:35,
            tbar:[toolbar]//此处加上'[]'与不加在页面显示的按钮有区别
        });
      //状态栏

        var southPanel = new Ext.Panel({
            region:"south",
            height:30,
            frame:false,
            border: false,
            bbar: new Ext.ux.StatusBar({
                id: 'statusbar',
                defaultText: '信息',
                text: 'Ready',
                iconCls: 'x-status-valid',
                items: [
                    '当前用户：',
                    {	
    	                id : 'sb_username',
                        text: '<s:property value="#session.adminUser.username"/>',
                        handler: function (){
                            var sb = Ext.getCmp('statusbar');
                            sb.setStatus({
                                text: '错误',
                                iconCls: 'x-status-error',
                                clear: true // auto-clear after a set interval
                            });
                        }
                    }
                ]
            })
        });
        
        var westPanel = new Ext.Panel({
            id:'westPanel',
        	title:'导航菜单',
        	region:'west',
        	width:'200',
        	split:true,
        	collapsible: true,
        	margins:'0 0 0 0',
            layout:'accordion',
            layoutConfig:{animate:false}/*,
            items : [
                     treePanel1,
                     treePanel2
                     ]*/
        });
		var centerPanel = new Ext.Panel({
			id : 'centerPanel',
			//title : '中心部分',
			region: 'center',
			split:true,
            layout:'fit', 
            items:[tabpanel]
			});

		var viewport = new Ext.Viewport({
			id : 'viewprot',
			layout : 'border',
			items : [
						northPanel,
						southPanel,
						westPanel,
						centerPanel
			]
		});
	}
    	
    Ext.onReady(InitMain); 
    addToolMenu();


    function addToolMenu(){
    	var arrMenu = new Array();
    	$.ajax({  
			url:'adminFindMenu',  
			type:'POST',  
			data:"{}",  
			dataType:'json',
			timeout: 100000,
			async:true,               
			error: function(a){                     
				alert('出错了');                 
			},   
			success:function (data) { 
				arrMenu = data.menuList; 
			    //$("#allUser").append("输出了：id:" + data.hello);  
			 //  alert(arrMenu);
			    //addToolMenu();
		        var toolbars = Ext.getCmp("toolbar");
		        var westPanel = Ext.getCmp("westPanel");
		        for(var i=0;i<arrMenu.length;i++){
		            var parentId = arrMenu[i].parentid;
		            if(parentId == 0){
			            var btnId = arrMenu[i].id;
			            var btnText = arrMenu[i].text;
			            var childrenarr = arrMenu[i].children;
					    //添加菜单按钮
			            var toolbtn = new Ext.Button({
				        	id : btnId,
						    text : btnText,
						  	xtype : "tbbutton",
						    cls : 'x-btn-text-icon',
						    listeners : {
						    	"click" : function(o,e){
						    	//alert(o.id);
						    	//展开对应的Panel(o为当前按扭的对象，可得到其id)
				            	var mainpanel = Ext.getCmp("panel" + o.id);
								mainpanel.expand(true); 
			            		}
						    }
			            });
			            toolbars.addItem(toolbtn);
			            //添加左侧菜单项
			           	var westSubPanel = new Ext.Panel({
			           		xtype : "treepanel",
			    			id : "panel" + btnId,
			    			title : btnText,
			    			border : false,
			    			layout:'fit',
			    			border: false,
			    			frame:true,
			    			items:
			    	            [{
			    	                 xtype:'treepanel',
			    	                 singleExpand:true,
			    	                 animate:true,
			    	                 autoScroll:true,
			    	                 containerScroll: true,
			    	                 border: false,
			    	                 rootVisible:false,
			    	                 lines:true,
			    	                 width:200,
			    	                 height:370,
			    	                 enableDD:false,
			    	                 dropConfig: {appendOnly:true},                          
			    	                 loader: new Ext.tree.TreeLoader({
			    						 preloadChildren: true,
			    					     clearOnLoad: false
			    						 //dataUrl:"json.aspx?Param=1"
			    						 }),                          
			    	                 root:new Ext.tree.AsyncTreeNode({
			    	                    id:"tree"+btnId,
			    	                    text: btnText,
			    	                    draggable:false,
			    	                    expanded:true,
			    						leaf:false,
			    						children:childrenarr
			    	                  })
			    	                  ,listeners:{"click": function(node,e){
			    								if (node.leaf)
			    								{//node.attributes.xxx得到树结点属性中存在的，但不是其本身属性的值
			    									//alert(node.text+"你点的是："+node.attributes.jspurl + "::w::" + node.id );
			    									var tabpaneltemp = Ext.getCmp("tab"+node.id);
			    									var tagerturl = node.attributes.jspurl;
			    									if (tabpaneltemp==null)
			    									{
			    										tabpaneltemp = new Ext.Panel
			    										({
			    								             id:"tab"+node.id,
			    								             xtype:"panel",
			    								             layout:'fit',
			    								             title:node.text,
			    								             closable:true,
			    								             border:false,
			    								             frame:false,//iconCls:'panel_icon',
			    											html:"<iframe scrolling='no' width='100%' height='100%'  frameborder='0' src='"+tagerturl+"'></iframe>"
			    										});
			    										Ext.getCmp("tabpanel").add(tabpaneltemp);
			    									}
			    									Ext.getCmp("tabpanel").setActiveTab("tab"+node.id);
			    								}							
			    							}}
			    	                 }]
			           	});
			           	westPanel.add(westSubPanel);
			           	toolbars.doLayout();
			           	westPanel.doLayout();
		            }
		            
		        }
			}  
			});
    }


  </script>
  </body>
</html>

